# Contributor: prspkt <prspkt@protonmail.com>
# Maintainer: prspkt <prspkt@protonmail.com>
pkgname=xscreensaver
pkgver=5.44
pkgrel=0
pkgdesc="Screensavers for X11 environment"
url="https://www.jwz.org/xscreensaver/"
arch="all"
license="GPL-2.0-or-later GPL-3.0-or-later 0BSD MIT"
depends="bc"
options="suid"
makedepends="gtk+-dev libjpeg-turbo-dev mesa-dev gettext-dev libxmu-dev perl
	libxml2-dev libglade-dev libxinerama-dev libxrandr-dev glu-dev sed"
subpackages="$pkgname-doc $pkgname-gl-extras:gl $pkgname-extras $pkgname-lang"
source="https://www.jwz.org/xscreensaver/xscreensaver-$pkgver.tar.gz"

_libexecdir=/usr/lib/xscreensaver
_confdir=/usr/share/xscreensaver/config

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--with-gtk \
		--libexecdir=$_libexecdir \
		--with-xinerama-ext \
		--with-xf86vmode-ext \
		--with-randr-ext
	make
}

package() {
	make install_prefix="$pkgdir" install
}

gl() {
	local _conf
	pkgdesc="An enhanced set of screensavers that require OpenGL"
	cd "$pkgdir"
	mkdir -p "$subpkgdir"/$_confdir
	scanelf -Rn . | awk '$2 ~ /libGL/ { print $3}' | while read f; do
		mkdir -p "$subpkgdir"/${f%/*}
		mv "$f" "$subpkgdir"/${f%/*}

		_conf=usr/share/xscreensaver/config/${f##*/}.xml
		if [ -f "$_conf" ]; then
			mv "$_conf" "$subpkgdir"/$_confdir
		fi
	done
}

extras() {
	pkgdesc="An enhanced set of screensavers"
	mkdir -p "$subpkgdir"/$_libexecdir \
		"$subpkgdir"/$_confdir
	mv "$pkgdir"/$_libexecdir/* "$subpkgdir"/$_libexecdir
	mv "$pkgdir"/$_confdir/* "$subpkgdir"/$_confdir
}

sha512sums="9d9144dec6f075c2d6a1c3cd45123a98d6d0cd732d6c3e3389e97b3f802b8f8765a188d1e35f97f123ca0a64661ea616b7b710577063c311da3d99d8439f1dae  xscreensaver-5.44.tar.gz"
